package com.ezlcp.user.task;

import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.ezlcp.user.listener.MyNacosListener;
import com.ezlcp.user.utils.NacosUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

 

/**
 * @author Elwin ZHANG
 * @description: 测试使用：nacos侦听<br/>
 * @date 2022/12/22 15:45
 */
//@Component
@Slf4j
public class InitTask {

    @Autowired
    private NacosUtils nacosUtils;

    private static boolean isAdd=false;

    @Scheduled(fixedDelayString = "6000000",initialDelay = 10000)
    public void setNacosListener() throws NacosException {
        if(isAdd){
            return;
        }
        ConfigService service=nacosUtils.getConfigService();
        service.addListener("abc.test","",new MyNacosListener());
        isAdd=true;
    }
}
